class SourcesController < ApplicationController
  
  def index
    @sources = Source.sorted(:paginate => true, :page => params[:page])
  end
  
  def new
    @source = Source.new
  end
  
  def create
    @source = Source.new(params[:source])
    if @source.save
      flash[:success] = "Source created successfully."
      redirect_to(:action => :index)
    else
      render(:action => :new)
    end
  end    
  
  def edit
    @source = Source.find(params[:id])
  end
  
  def update
    @source = Source.find(params[:id])
    if @source.update_attributes(params[:source])
      flash[:success] = "Source updated successfully."
      redirect_to(:action => :index)
    else
      render(:action => :new)
    end
  end
  
  def destroy
    @source = Source.find(params[:id])
    begin
      @source.destroy  
      flash[:success] = "Source deleted successfully" 
    rescue 
      flash[:error] = $!.to_s
    end
    redirect_to(:action => :index)
  end
end
